package com.example.qa.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.qa.commonutils.R;
import com.example.qa.entity.ZhComment;
import com.example.qa.service.ZhCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author testjava
 * @since 2021-03-03
 */
@CrossOrigin
@RestController
@RequestMapping("/qa/comment")
public class ZhCommentController {
    @Autowired
    public ZhCommentService commentService;
@GetMapping("/detail/{answerId}")
    public R getCommentByAnswerId(@PathVariable String answerId)
{
    QueryWrapper<ZhComment>wrapper=new QueryWrapper<>();
    wrapper.eq("answer_id",answerId);
    wrapper.orderByAsc("gmt_create");
    List<ZhComment> commentList = commentService.list(wrapper);
    return R.ok().data("list",commentList);
}
@PostMapping("/add")
    public R addComment(@RequestBody ZhComment comment)
{
    commentService.save(comment);
    return R.ok();
}
}

